﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>产品列表</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <link href="/style/admin/style/adminStyle.css" rel="stylesheet" type="text/css" />
        <script type="text/javascript" src="/style/admin/js/jquery-2.1.4.min.js" ></script>
        <link rel="stylesheet" href="/editor/themes/default/default.css" />
        <link rel="stylesheet" href="/editor/plugins/code/prettify.css" />
        <script charset="utf-8" src="/editor/kindeditor-all.js"></script>
        <script charset="utf-8" src="/editor/zh-CN.js"></script>
        <script charset="utf-8" src="/editor/plugins/code/prettify.js"></script>
    </head>
    <body>
        <div class="wrap">
            <div class="page-title">
                <span class="modular fl"><i class="add"></i><em>编辑/添加产品</em></span>
                <span class="modular fr"><a href="/admin/types" class="pt-link-btn">产品列表</a></span>
            </div> 
            <form id="formAdd" name="man"  action="/admin/types/updates" method="post" enctype="multipart/form-data">
                {{ csrf_field() }}
                <table class="list-style">
                    <tr>
                        <td style="text-align:right;width:15%;">产品名称：</td>
                        <td><input type="text" name="title" value="{{$data->title}}" class="textBox length-long"/></td>
                        <input type="hidden" name="id" value="{{$data->id}}" class="textBox length-long"/>
                    </tr>
                    <tr>
                        <td style="text-align:right;">产品分类：</td>
                        <td>
                            <select name="cid" class="textBox"> 
                                <?php
                                $info1 = \DB::table('types')->where("id", $data->cid)->first();
                                ?>
                                <option value="{{$info1->id}}">{{$info1->name}}</option>  
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td style="text-align:right;">市场价：</td>
                        <td>
                            <input type="text" name="m_price" value="{{$data->m_price}}" class="textBox length-short"/>
                            <span>元</span>
                        </td>
                    </tr>
                    <tr>
                        <td style="text-align:right;">会员价：</td>
                        <td>
                            <input type="text" name="price" value="{{$data->price}}" class="textBox length-short"/>
                            <span>元</span>
                        </td>
                    </tr>
                    <tr>
                        <td style="text-align:right;">库存：</td>
                        <td>
                            <input type="text" name="num" value="{{$data->num}}" class="textBox length-short"/>
                            <span>盘</span>
                        </td>
                    </tr>
                    <tr>
                        <td style="text-align:right;">产品关键词：</td>
                        <td><input type="text" name="keywords" value="{{$data->keywords}}" class="textBox length-long"/></td>
                    </tr>
                    <tr>
                        <td style="text-align:right;">产品描述：</td>
                        <td><input type="text" name="info" value="{{$data->info}}" class="textBox length-long"/></td>
                    </tr>
                    <tr>
                        <td style="text-align:right;">推荐至：</td>
                        <td>
                            @if($data->is_best==1)
                            <input type="checkbox" name="is_best" value="{{$data->is_best}}" checked id="jingpin"/> 
                            @else
                            <input type="checkbox" name="is_best" value="{{$data->is_best}}" id="jingpin"/> 
                            @endif

                            <label for="jingpin">精品</label>

                            @if($data->is_news==1)
                            <input type="checkbox" name="is_news" value="{{$data->is_news}}" checked id="xinpin"/> 
                            @else
                            <input type="checkbox" name="is_news" value="{{$data->is_news}}" id="xinpin"/> 
                            @endif   
                            <label for="xinpin">新品</label>

                            @if($data->is_host==1)
                            <input type="checkbox" name="is_host" value="{{$data->is_host}}" checked id="rexiao"/> 
                            @else
                            <input type="checkbox" name="is_host" value="{{$data->is_host}}" id="rexiao"/> 
                            @endif 
                            <label for="rexiao">热销</label>
                        </td>
                    </tr>

                    <tr>
                        <td style="text-align:right;">产品主图片：</td>
                        <td>
                            <input type="file" accept="image/*" id="up_img" name="photo"  onchange="fileUpLoad(this);" class="hide"/>
                            <label for="up_img" class="labelBtnAdd">+</label>
                            <div id="showImg">
                                <img src="{{$data->img}}" width="60" height="60"/>
                            </div>
                        </td>
                    </tr>

                    <tr>
                        <td style="text-align:right;">产品子图：</td>
                        <td>
                            <input type="file" name="subgraph[]"  multiple="multiple" id="up_imgs" onchange="fileUpLoads(this);" class="hide"/>
                            <label for="up_imgs" class="labelBtn2">本地上传(最多选择N张)</label>
                            <span class="labelBtn2" onclick="call();">取消</span>  
                        </td>
                    </tr>
                    <tr>
                        <td style="text-align:right;"></td>
                        <td>
                            <div id="showImgs">
                                @foreach($info as $i)
                                <img class="old_zi" src='{{$i->img}}' width="60" height="60"/>
                                @endforeach
                            </div>
                        </td>
                    </tr>

                    <tr>
                        <td style="text-align:right;">产品详情：</td>
                        <td><textarea id="editor_id" name="text" style="width:700px;height:300px;"> 
                                 {{$data->text}}
                            </textarea></td>
                    </tr>
                    <tr>
                        <td style="text-align:right;"></td>
                        <td><input type="submit" value="发布新商品" class="tdBtn"/></td>
                    </tr>
                </table>
            </form>
        </div>
    </body>
    <script type="text/javascript">
        //主图上传容器
        var imgCont = document.getElementById("showImg");
        var ipt = document.getElementById("up_img");
        //子图上传容器
        var imgConts = document.getElementById("showImgs");
        var ipts = document.getElementById("up_imgs");
        function fileUpLoad(_this) {//主图上传方法
            var file = _this.files[0];
            if (!FileReader) {
                alert("你的浏览器不支持H5的FileReader");
                ipt.setAttribute("disabled", "disabled");//浏览器不支持禁用input type='file'文件上传标签  
                return;
            }
            var fileReader = new FileReader();
            fileReader.readAsDataURL(file);//将文件读取为Data URL 读取结果放在result中  
            fileReader.onload = function (e) {
                var img = '<img src="' + this.result + '"/ width=60 height=60>';
                imgCont.innerHTML = img;
                console.log(this.result);
            }
        }

        function fileUpLoads(_this) {//子图上传方法  
            $(".old_zi").css("display", "none");
            if (!FileReader) {
                alert("你的浏览器不支持H5的FileReader");
                ipts.setAttribute("disabled", "disabled");//浏览器不支持禁用input type='file'文件上传标签  
                return;
            }
            for (i = 0; i < _this.files.length; i++) {
                var reader = new FileReader();
                reader.readAsDataURL(_this.files[i]);
                reader.onload = function (e) {
                    //多图预览 
                    if ($(".zi").length < 5) {
                        var img1 = '<img class="zi" src="' + this.result + '"/ width=60 height=60>';
                        imgConts.innerHTML += img1;
                    } else {
                        alert('最多5张图片');
                    }
                }
            }
        }
        function call() {
            ipts.value = "";
            $(".old_zi").css("display", "");
            $(".zi").remove();
        }

        KindEditor.ready(function (K) {
            var editor = K.create('textarea[name="text"]', {
                cssPath: '/editor/plugins/code/prettify.css',
                uploadJson: '/editor/php/upload_json.php',
                fileManagerJson: '/editor/php/file_manager_json.php',
                allowFileManager: true,
                afterCreate: function () {
                    var self = this;
                    K.ctrl(document, 13, function () {
                        self.sync();
                        K('form[name=man]')[0].submit();
                    });
                    K.ctrl(self.edit.doc, 13, function () {
                        self.sync();
                        K('form[name=man]')[0].submit();
                    });
                }
            });
//            html = editor.html();
//            // 同步数据后可以直接取得textarea的value
//            editor.sync();
//            html = document.getElementById('editor_id').value; // 原生API
//            html = K('#editor_id').val(); // KindEditor Node API
//            
//            alert(html);
            prettyPrint();
        });
    </script>

</html>